package com.ktgj.train.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.train.domain.vo.TrainOrderItemVo;
import com.ktgj.train.service.ITrainOrderitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.train.domain.TrainOrderitem;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 子订单Controller
 * 
 * @author ruoyi
 * @date 2021-11-29
 */
@ControllerAdvice
@RestController
@RequestMapping("/orderitem")
public class TrainOrderitemController extends BaseController
{
    @Autowired
    private ITrainOrderitemService trainOrderitemService;

    /**
     * 查询子订单列表
     */
    @PreAuthorize(hasPermi = "train:orderitem:list")
    @GetMapping("/list")
    public TableDataInfo list(TrainOrderitem trainOrderitem)
    {
        startPage();
        List<TrainOrderitem> list = trainOrderitemService.selectTrainOrderitemList(trainOrderitem);
        return getDataTable(list);
    }

    /**
     * 导出子订单列表
     */
    @PreAuthorize(hasPermi = "train:orderitem:export")
    @Log(title = "子订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainOrderitem trainOrderitem) throws IOException
    {
        List<TrainOrderitem> list = trainOrderitemService.selectTrainOrderitemList(trainOrderitem);
        ExcelUtil<TrainOrderitem> util = new ExcelUtil<TrainOrderitem>(TrainOrderitem.class);
        util.exportExcel(response, list, "子订单数据");
    }

    /**
     * 获取子订单详细信息
     */
    @PreAuthorize(hasPermi = "train:orderitem:query")
    @GetMapping(value = "/{orderitemid}")
    public AjaxResult getInfo(@PathVariable("orderitemid") Long orderitemid)
    {
        return AjaxResult.success(trainOrderitemService.selectTrainOrderitemById(orderitemid));
    }

    /**
     * 新增子订单
     */
    @PreAuthorize(hasPermi = "train:orderitem:add")
    @Log(title = "子订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainOrderitem trainOrderitem)
    {
        return toAjax(trainOrderitemService.insertTrainOrderitem(trainOrderitem));
    }

    /**
     * 修改子订单
     */
    @PreAuthorize(hasPermi = "train:orderitem:edit")
    @Log(title = "子订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainOrderitem trainOrderitem)
    {
        return toAjax(trainOrderitemService.updateTrainOrderitem(trainOrderitem));
    }

    @PostMapping("/updateByTrainOrderItem")
    public AjaxResult updateByTrainOrderItem(@RequestBody Long orderId) {
        return toAjax(trainOrderitemService.updateByTrainOrderItem(orderId));
    }

    /**
     * 删除子订单
     */
    @PreAuthorize(hasPermi = "train:orderitem:remove")
    @Log(title = "子订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderitemids}")
    public AjaxResult remove(@PathVariable Long[] orderitemids)
    {
        return toAjax(trainOrderitemService.deleteTrainOrderitemByIds(orderitemids));
    }
}
